home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiniExamples / AppKit / CellScrollView / Controller.m < prev    next >
Encoding:
Text File  |  1993-06-22  |  1.6 KB  |  74 lines

  1. /* You may freely copy, distribute, and reuse the code in this example.
  2.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  3.  * fitness for any particular use.
  4.  */
  5.  
  6.  
  7. #import "Controller.h"
  8. #import "FooObject.h"
  9. #import "CellScrollView.h"
  10. #import "FooCell.h"
  11.  
  12. @implementation Controller
  13.  
  14. - appDidInit:sender
  15. {
  16.   [self addFooObject:self];
  17.   [cellScrollView loadCellsFrom:fooObjects];
  18.   cellMatrix = [cellScrollView cellMatrix];
  19.   return self;
  20. }
  21.  
  22. - init
  23. {
  24.   [super init];
  25.   fooObjects = [[List alloc] init];
  26.   return self;
  27. }
  28.  
  29. - free
  30. {
  31.   [fooObjects free];
  32.   return [super free];
  33. }
  34.  
  35. - addFooObject:sender
  36. {
  37.   FooObject *fooObject = [[FooObject alloc] init];
  38.   [fooObjects addObject:fooObject];
  39.   [cellScrollView loadCellsFrom:fooObjects];
  40.   /*
  41.    * Assumptions in this next line:
  42.    *    There are as many fooCells as there are fooObjects
  43.    *    We've added the new fooObject at the end of the list.
  44.    *    We want to display the fooObject we just added and highlight it.
  45.    * In short, this is a hack.
  46.    */
  47.   [cellMatrix scrollCellToVisible:[fooObjects count]-1 :0];
  48.   [cellMatrix selectCellAt:[fooObjects count]-1:0];
  49.   return self;
  50. }
  51.  
  52. - deleteFooObjects:sender
  53. /*
  54.  * Delete all selected fooObjects.
  55.  */
  56. {
  57.   int i;
  58.  
  59.   for (i=[cellMatrix cellCount]-1; i>=0; i--) {
  60.     FooCell *cell = [cellMatrix cellAt:i:0];
  61.     if ([cell isHighlighted]) {
  62.       /*
  63.        * If a cell is highlighted, remove (and free) the corresponding item
  64.        * from the list of fooObjects.
  65.        */
  66.       [[fooObjects removeObject:[cell fooObject]] free];
  67.     }
  68.   }
  69.   [cellScrollView loadCellsFrom:fooObjects];
  70.   return self;
  71. }
  72.  
  73. @end
  74.